'use strict';

module.exports = app => {
    const { Sequelize, model } = app

    const Model = model.define('minaHelper', {
        id:{
            type: Sequelize.STRING.BINARY,
            defaultValue: Sequelize.UUIDV1,
            primaryKey: true
        },
        openid: {
            type: Sequelize.STRING(50),
            allowNull: false,
            unique: true,
        },
        unionid: {
            type: Sequelize.STRING(50),
        },
        nickName: {
            type: Sequelize.STRING(50),
        },
        avatarUrl: {
            type: Sequelize.STRING,
        },
        gender: {
            type: Sequelize.STRING(1),
        },
        city: {
            type: Sequelize.STRING(20),
        },
        province: {
            type: Sequelize.STRING(20),
        },
        country: {
            type: Sequelize.STRING(20),
        },
        language: {
            type: Sequelize.STRING(20),
        },
        phone: {
            type: Sequelize.STRING(20),
        },
        role: {
            type: Sequelize.INTEGER(1),
        },
    }, {
        freezeTableName: true,
        tableName: 'mina_helper',
    })

    Model.associate = function() {
        model.MinaHelper.belongsTo(model.Corp)
        model.MinaHelper.belongsTo(model.CorpUser)
        model.MinaHelper.belongsTo(model.Driver)
        model.MinaHelper.belongsTo(model.Agent)
        model.Corp.hasMany(model.MinaHelper)
        model.CorpUser.hasOne(model.MinaHelper)
        model.Driver.hasOne(model.MinaHelper)
        model.Agent.hasOne(model.MinaHelper)
    }

    return Model
}